<Script>
function mailform(address)
{
 window.open('mailbox.php?address='+address,'','left=50, top=50, width=400, height=250, toolbar=no, scrollbars=no, status=no, resizable=no');
}
</Script>
<style>
.table_box { border:1px solid #999999;font-size: 12px; }
.picture_box { border:1px solid #555555; background-color:#AAAAAA; }
.information_box { border:1px solid #888888; }
.submit_box { 
	border:1px solid #9999BB;font-size: 12px; background-color:#AAAADD;
	color:#222222;
 }
</style>
<?
	include("php/functions.php");

if ($way == "condition") {

	// init where syntax
	$where_syntax="";

	// Get post data

	// condition for gender
	if ($gender=="any" || $gender == "") 
	{ 
		$where_syntax = "gender != ''";
	} else if ($gender=="male" || $gender=="female") {
		$where_syntax = "gender = '".$gender."'";
	}

	$where_syntax = $where_syntax." AND ";

	if ($age=="any" || $age == "")
	{
		$where_syntax = $where_syntax." 1 = 1";
	} else {
		switch($age)
		{
			case "1":
				$where_syntax = $where_syntax." age < 21";
				break;
			case "2":
				$where_syntax = $where_syntax." age > 20 AND age < 25";
				break;
			case "3":
				$where_syntax = $where_syntax." age > 24 AND age < 28";
				break;
			case "4":
				$where_syntax = $where_syntax." age > 27 AND age < 31";
				break;
			case "5":
				$where_syntax = $where_syntax." age > 30 AND age < 34";
				break;
			case "6":
				$where_syntax = $where_syntax." age > 33";
				break;
	
		}
	}
	// End of query condition syntax

	// call query
	if ($where_syntax != "")
		$result=func2($where_syntax);
	else
		$result=func2("1 = 1");
} else if ($way == "keyword") {
	if ($keyword!="") {
		$result=func3($keyword);
	} else {
		exit(1);
	}
} else {
	exit(1);
}
	
	$result_cnt=$result["num_results"];

	if ($result_cnt == 0)
		echo " Oh my god. there is no person for you";
	else
	{

	$i=(rand(0,$result_cnt-1));
?>
	<div align=center>
	<table border=0 width=420 class=table_box>
<?

	{
		// here is delay point. interpreter will be change his own face.
		?>
			<tr bgcolor=#bbbbdd>	
				<td colspan=4 align=center>
					<?=$result[$i]["name"]?>
				</td>
			</tr>
			<tr>
				<td width=160px height=160px align=center>
	<table width=160 height=160 align=center class=picture_box>
					<tr>
					<td align=center width=100% height=100%>
						<? if ($result[$i]['hasPicture']) { ?>
						<img src="php/picture.php?file_name=<?=$result[$i]['id']?>" border=1>
						<?	
						   } else {
							echo "Picture";
						   }
						?>
					</td>
					</tr>
					</table>
				</td>
				<td colspan=3 valign=top>
        <table width=100% height=100% align=center class=information_box border=0>
                                        <tr height=14>
                                        <td align=center width=100% colspan=2>
                                                <font size=2>INFORMATION</font>
                                        </td>
                                        </tr>
					<tr><td colspan=2>&nbsp;</td></tr>
					<tr height=14>
					<td width=40%>&nbsp;&nbsp;<FONT size=2>GENDER</td>
		<td width=60%><FONT size=2><?=$result[$i]["gender"]?></td>
					</tr>
                                        <tr height=14>
                                        <td width=40>&nbsp;&nbsp;<FONT size=2>AGE</td>
                                        <td><FONT size=2><?=$result[$i]["age"]?></td>
                                        </tr>
					<tr height=100%><td colspan=2>&nbsp;</td></tr>
                                        <tr><td colspan=2>&nbsp;</td></tr>
                                        <tr height=14>
                                        <td width=40%>&nbsp;&nbsp;<FONT size=2>KEYWORD</td>
                <td width=60%><FONT size=2><?=$result[$i]["keyword"]?></td>
                                        </tr>
                                        </table>

				</td>
			</tr>
			<tr>
				<td colspan=4 align=center>

	<input type=submit class=submit_box value='SEND TO MESSAGE' OnClick="javascript:mailform('<?=$result[$i]['id']?>')">
				</td>
			</tr>
		<?
	}
?>
	</table></div>
<?
	}
?>
